package cn.signalpha.modules.com.service;

import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.com.entity.UserBank;
import cn.signalpha.modules.com.mapper.UserBankMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Map;

import static cn.signalpha.common.cache.CacheNames.ORDER_CONFIRM;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class UserBankService extends ServiceImpl<UserBankMapper, UserBank> {

    /**
	 * 自定义Wrappers
	 */
    public QueryWrapper<UserBank> selectUserBankWrapper(Map<String, Object> params) {
        QueryWrapper<UserBank> wrapper = Wrappers.query();
        wrapper.lambda().eq(ObjectUtil.isNotEmpty(params.get("userId")), UserBank::getUserId, params.get("userId"));
        wrapper.lambda().orderByDesc(UserBank::getId);
        return wrapper;
    }

	@CachePut(cacheNames = ORDER_CONFIRM, key = "#userId")
	public UserBank putUserBankCache(Long userId, UserBank userBank) {
		return userBank;
	}
	@Cacheable(cacheNames = ORDER_CONFIRM, key = "#userId")
	public UserBank getUserBankCache(Long userId) {
		return null;
	}
	@CacheEvict(cacheNames = ORDER_CONFIRM, key = "#userId")
	public void removeUserBankCache(Long userId) {
	}

}

